package se.chalmers.tda366.crumble.gui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;

import se.chalmers.tda366.crumble.gui.utils.GuiObserv;
import se.chalmers.tda366.crumble.resources.Constants;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CrumbleFrame extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JButton addFeedButton, removeCategoryButton, addCategoryButton, refreshButton, configureFeedsButton, removeFeedButton;
	private JLabel statusLabel, logoLabel;
	private JToolBar statusBar, toolBar;
	private JPanel topPanel, entertainmentPanel, frontpagePanel, sportPanel,
			newsPanel, businessPanel, logoPanel, toolBarPanel, statusBarPanel;
	private JTabbedPane categoryTabbedPane;

	public CrumbleFrame() {
		super();
		initGUI();
		initCtrl();
	}
	
	private void initCtrl() {
		addFeedButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GuiObserv.getInstance().fireNotify(null, Constants.Actions.SHOW_ADD_FEED_DIALOG);
			}
		});
		configureFeedsButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GuiObserv.getInstance().fireNotify(null, Constants.Actions.SHOW_CONFIGURE_FEEDS_DIALOG);
			}
		});
		refreshButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GuiObserv.getInstance().fireNotify(null, Constants.Actions.REFRESH_FEEDS);
			}
		});
		addCategoryButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GuiObserv.getInstance().fireNotify(null, Constants.Actions.SHOW_ADD_CATEGORY_DIALOG);
			}
		});
		removeCategoryButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GuiObserv.getInstance().fireNotify(null, Constants.Actions.SHOW_REMOVE_CATEGORY_DIALOG);
			}
		});
		removeFeedButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GuiObserv.getInstance().fireNotify(null, Constants.Actions.SHOW_REMOVE_FEED_DIALOG);
			}
		});
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			this.setTitle("Crumble.rss");
			this.setIconImage(Toolkit.getDefaultToolkit().getImage("../images/Crumble_icon32.png"));
			
			{
				categoryTabbedPane = new JTabbedPane();
				getContentPane().add(categoryTabbedPane, BorderLayout.CENTER);
				categoryTabbedPane.setPreferredSize(new java.awt.Dimension(516, 256));
				categoryTabbedPane.setBackground(new java.awt.Color(255,255,255));
				categoryTabbedPane.setForeground(new java.awt.Color(0,0,0));
				categoryTabbedPane.setOpaque(true);
				categoryTabbedPane.setBorder(BorderFactory.createCompoundBorder(
						null, 
						null));
				{
					frontpagePanel = new JPanel();
					newsPanel = new JPanel();
					businessPanel = new JPanel();
					entertainmentPanel = new JPanel();
					sportPanel = new JPanel();
					
					categoryTabbedPane.addTab("Front Page", null, frontpagePanel, null);
					frontpagePanel.setPreferredSize(new java.awt.Dimension(646, 244));
					frontpagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

					categoryTabbedPane.addTab("News", null, newsPanel, null);		
					categoryTabbedPane.addTab("Business", null, businessPanel, null);
					categoryTabbedPane.addTab("Entertainment", null, entertainmentPanel, null);
					categoryTabbedPane.addTab("Sports", null, sportPanel, null);
				}
			}
			
			{
				topPanel = new JPanel();
				BorderLayout topPanelLayout = new BorderLayout();
				getContentPane().add(topPanel, BorderLayout.NORTH);
				topPanel.setPreferredSize(new java.awt.Dimension(651, 100));
				topPanel.setLayout(topPanelLayout);
				topPanel.setBackground(new java.awt.Color(255,255,255));
				
				toolBarPanel = new JPanel();
				BoxLayout toolBarPanelLayout = new BoxLayout(toolBarPanel, javax.swing.BoxLayout.X_AXIS);
				toolBarPanel.setLayout(toolBarPanelLayout);
				topPanel.add(toolBarPanel, BorderLayout.NORTH);
				toolBarPanel.setPreferredSize(new java.awt.Dimension(647, 26));
				toolBarPanel.setBackground(new java.awt.Color(209,211,217));
				toolBarPanel.setLocation(new java.awt.Point(0, 0));
				{
					toolBar = new JToolBar();
					toolBarPanel.add(toolBar);
					toolBar.setBackground(new java.awt.Color(238,238,238));
					toolBar.setOpaque(true);
					toolBar.setFloatable(false);
					toolBar.setPreferredSize(new java.awt.Dimension(651, 55));
					{
						addFeedButton = new JButton("Subscribe");
						addFeedButton.setIcon(new ImageIcon(getClass().getResource("../images/plus_16.png")));
						addFeedButton.setMnemonic(java.awt.event.KeyEvent.VK_S);
						toolBar.add(addFeedButton);
	
						configureFeedsButton = new JButton("Configure subscriptions");
						configureFeedsButton.setIcon(new ImageIcon(getClass().getResource("../images/pencil_16.png")));
						configureFeedsButton.setMnemonic(java.awt.event.KeyEvent.VK_C);
						toolBar.add(configureFeedsButton);

						removeFeedButton = new JButton("Remove subscription");
						removeFeedButton.setIcon(new ImageIcon(getClass().getResource("../images/delete_16.png")));
						toolBar.add(removeFeedButton);

						toolBar.add(new JSeparator(SwingConstants.VERTICAL));
						
						addCategoryButton = new JButton("Add Category");
						addCategoryButton.setIcon(new ImageIcon(getClass().getResource("../images/plus_16.png")));
						toolBar.add(addCategoryButton);

						removeCategoryButton = new JButton("Remove Category");
						removeCategoryButton.setIcon(new ImageIcon(getClass().getResource("../images/delete_16.png")));
						toolBar.add(removeCategoryButton);

						toolBar.add(new JSeparator(SwingConstants.VERTICAL));

						refreshButton = new JButton("Refresh");
						refreshButton.setIcon(new ImageIcon(getClass().getResource("../images/reload_16.png")));
						toolBar.add(refreshButton);
					}
				}
				
				logoPanel = new JPanel();
				BoxLayout logoPanelLayout = new BoxLayout(logoPanel, javax.swing.BoxLayout.X_AXIS);
				logoPanel.setBackground(new java.awt.Color(255,255,255));
				logoPanel.setLayout(logoPanelLayout);
				
				{
					logoLabel = new JLabel(new ImageIcon(getClass().getResource("../images/Crumble_logo.png")));
					FlowLayout logoLabelLayout = new FlowLayout();
					logoLabelLayout.setHgap(0);
					logoLabelLayout.setVgap(0);
					logoLabelLayout.setAlignment(FlowLayout.LEFT);
					logoLabel.setLayout(logoLabelLayout);
					logoLabel.setText(" ");
					logoLabel.setPreferredSize(new java.awt.Dimension(490, 70));
					logoLabel.setHorizontalAlignment(SwingConstants.LEFT);
					logoLabel.setHorizontalTextPosition(SwingConstants.LEFT);
					logoLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
					logoPanel.add(logoLabel);
				}
				
				topPanel.add(logoPanel, BorderLayout.CENTER);
				
				statusBarPanel = new JPanel();
				BoxLayout statusBarPanelLayout = new BoxLayout(statusBarPanel, javax.swing.BoxLayout.Y_AXIS);
				statusBarPanel.setLayout(statusBarPanelLayout);
				this.add(statusBarPanel, BorderLayout.SOUTH);
				statusBarPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				statusBarPanel.setBackground(new java.awt.Color(234,235,236));
				statusBarPanel.setPreferredSize(new java.awt.Dimension(647, 17));
				{
					statusBar = new JToolBar();
					statusBarPanel.add(statusBar);
					statusBar.setFloatable(false);
					{
						statusLabel = new JLabel();
						statusBar.add(getStatusLabel());
						statusLabel.setText("Program loaded");
						statusLabel.setPreferredSize(new java.awt.Dimension(355, 16));
					}
				}

				super.repaint();
				
			}
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public JTabbedPane getCategoryTabbedPane() {
		return categoryTabbedPane;
	}
	public JPanel getFrontpagePanel() {
		return frontpagePanel;
	}
	
	public JLabel getStatusLabel() {
		return statusLabel;
	}
}
